//
//  HelpView.m
//  Weibbo
//
//  Created by 李 林刚 on 13-8-12.
//  Copyright (c) 2013年 Omnivores. All rights reserved.
//

#import "HelpView.h"

@interface HelpView ()
{
    UIImageView   *imageView;
    NSArray       *imageArr;
    UIButton      *button;
    int           currenImageIndex;
}

@end

@implementation HelpView
@synthesize delagate;

-(void)dealloc
{
    UIRelease(imageView);
    UIRelease(imageArr);
    UIRelease(button);
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        currenImageIndex = 0;
        imageArr = [[NSArray alloc]initWithObjects:@"1.png",@"2.png",@"3.png",@"4.png", nil];
        imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame))];
        [imageView setImage:[UIImage imageNamed:[imageArr objectAtIndex:currenImageIndex]]];
        [self addSubview:imageView];
        
        button = [[UIButton alloc]initWithFrame:CGRectMake((CGRectGetWidth(frame)-60)/2, CGRectGetHeight(frame)-40, 60, 20)];
        [button setBackgroundColor:UIGreenColor];
        [button addTarget:self action:@selector(NextStep) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
    }
    return self;
}


-(void)NextStep
{
    currenImageIndex++;
    if (currenImageIndex==[imageArr count]) {
        if ([delagate respondsToSelector:@selector(HelpViewDelegateRemove)]) {
            [delagate HelpViewDelegateRemove];
        }
        return;
    }
    CATransition *transition = [CATransition animation];
    transition.duration = .5;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.subtype = kCATransitionFromBottom;
    [imageView setImage:[UIImage imageNamed:[imageArr objectAtIndex:currenImageIndex]]];
    [imageView.layer addAnimation:transition forKey:nil];
    if (currenImageIndex==[imageArr count]-1)
    {
        [button setBackgroundColor:UIYellowColor];
    }
  }
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
